package org.opentcs.kcvehicle.communication.kc.udp.agv.param.function.x17;

import java.util.Arrays;
import org.opentcs.kcvehicle.communication.kc.common.byteutils.ByteUtils;

public class QueryRobotRunStatusRsp {
  //本体温度 ,8个字节 ,double
  private double temp;
  //位置的 X 坐标 , 8个字节 ,double
  private double currentX;
  //位置的 Y 坐标,8个字节 ,double
  private double currentY;
  //位置的 角度 ,8个字节 ,double
  private double currentAngle;
  //电池电量,,8个字节 ,double
  private double battery;
  //是否被阻挡,1个字节,byte
  private byte isBlocked;
  //是否在充电,1个字节,byte
  private byte isCharging;
  //运行模式,1个字节,byte
  private byte runMode;
  //地图载入状态,1个字节,byte
  private byte mapLoadState;
  //当前的目标点 id,U32 ,4个字节
  public Integer currentTargetId;

  //前进速度,8个字节,double
  private double forwardSpeed;
  //转弯速度,8个字节,double
  private double turnSpeed;
  //电池电压（充电为正，放电为负）,8个字节,double
  private double batteryVoltage;
  //电流（充电为正，放电为负）,double
  private double electricCurrent;
  //当前任务状态,1个字节,byte
  private byte taskState;
  //保留，1个字节
  private byte retain1;
  //地图版本号,2个字节
  private short mapVersion;
  //保留，4个字节
  private byte[] retain2;
  //累计行驶里程（单位 m）,8个字节
  private double cumulativeMileage;
  //本次运行时间（单位 ms）,8个字节
  private double currentRunTime;
  //累计运行时间（单位 ms）,8个字节
  private double cumulativeRunTime;
  //机器人定位状态,1个字节
  public byte robotLocalizationState;
  //保留，3个字节
  private byte[] retain3;
  //地图数量，U32,4个字节
  private Integer mapNum;
  //当前地图名称,64字节
  private String currentMapName;
  //置信度,4个字节
  private float confidence;
  //保留，4个字节
  private byte[] retain4;

  public QueryRobotRunStatusRsp(byte[] src) {
    this.temp = ByteUtils.bytesToDouble(src, 0);
    this.currentX = ByteUtils.bytesToDouble(src, 8);
    this.currentY = ByteUtils.bytesToDouble(src, 16);
    this.currentAngle = ByteUtils.bytesToDouble(src, 24);
    this.battery = ByteUtils.bytesToDouble(src, 32);
    this.isBlocked = src[40];
    this.isCharging = src[41];
    this.runMode = src[42];
    this.mapLoadState = src[43];
    this.currentTargetId = ByteUtils.bytesToInt(src, 44);
    this.forwardSpeed = ByteUtils.bytesToDouble(src, 48);
    this.turnSpeed = ByteUtils.bytesToDouble(src, 56);
    this.batteryVoltage = ByteUtils.bytesToDouble(src, 64);
    this.electricCurrent = ByteUtils.bytesToDouble(src, 72);
    this.taskState = src[80];
    this.retain1 = src[81];
    this.mapVersion = ByteUtils.bytesToShortLitt(src, 82);
    this.retain2 = ByteUtils.copyBytes(src, 84, 4);
    this.cumulativeMileage = ByteUtils.bytesToDouble(src, 88);
    this.currentRunTime = ByteUtils.bytesToDouble(src, 96);
    this.cumulativeRunTime = ByteUtils.bytesToDouble(src, 104);
    this.robotLocalizationState = src[112];
    this.retain3 = ByteUtils.copyBytes(src, 113, 3);
    this.mapNum = ByteUtils.bytesToInt(src, 116);
    this.currentMapName = ByteUtils.bytesToString(src, 120, 64);
    this.confidence = ByteUtils.bytesToFloat(src, 184);
    this.retain4 = ByteUtils.copyBytes(src, 188, 4);
  }

  @Override
  public String toString() {
    return "QueryRobotRunStatusRsp{" +
        "temp=" + temp +
        ", currentX=" + currentX +
        ", currentY=" + currentY +
        ", currentAngle=" + currentAngle +
        ", battery=" + battery +
        ", isBlocked=" + isBlocked +
        ", isCharging=" + isCharging +
        ", runMode=" + runMode +
        ", mapLoadState=" + mapLoadState +
        ", currentTargetId=" + currentTargetId +
        ", forwardSpeed=" + forwardSpeed +
        ", turnSpeed=" + turnSpeed +
        ", batteryVoltage=" + batteryVoltage +
        ", electricCurrent=" + electricCurrent +
        ", taskState=" + taskState +
        ", retain1=" + retain1 +
        ", mapVersion=" + mapVersion +
        ", retain2=" + Arrays.toString(retain2) +
        ", cumulativeMileage=" + cumulativeMileage +
        ", cuttentRunTime=" + currentRunTime +
        ", cumulativeRunTime=" + cumulativeRunTime +
        ", robotLocalizationState=" + robotLocalizationState +
        ", retain3=" + Arrays.toString(retain3) +
        ", mapNum=" + mapNum +
        ", currentMapName='" + currentMapName + '\'' +
        ", confidence=" + confidence +
        ", retain4=" + Arrays.toString(retain4) +
        '}';
  }
}
